
$(function(e){
	dataInit();
});

function dataInit(){
	eventInit();
	$('#messageTable').bootstrapTable({
		url: path+'23ec3172230b4f4899a656b65072e41f', method: 'post', striped: true, cache: false, pagination: true,
        contentType: "application/x-www-form-urlencoded", sidePagination: "server", pageSize: 10, uniqueId: "id", detailView: false,
        queryParams: function (params) {
        	return  { limit: params.limit, offset: params.offset, searchParams : $("#searchParams").val()};
        },//传递参数（*）
        columns:[{field: 'Number', title: '序号', align: 'center', width: '50', formatter: function (value, row, index) {
        			return index+1;
        		}}, 
        		{field: 'accountNumber', title: '门牌号', align: 'center', width: '120', formatter: function (value, row, index) {
        			if(isNull(value)){
	            		value = '-';
	            	}
        			return '<a style="word-wrap:break-word;">'+value+'</a>';
	            }},
	            {field: 'name', title: '姓名', align: 'center', width: '100', formatter: function (value, row, index) {
	            	if(isNull(value)){
	            		value = '-';
	            	}
	            	return '<a style="word-wrap:break-word;">'+value+'</a>';
	            }},
	            {field: 'tel', title: '联系方式', align: 'center', width: '100', formatter: function (value, row, index) {
	            	if(isNull(value)){
	            		value = '-';
	            	}
	            	return '<a style="word-wrap:break-word;">'+value+'</a>';
	            }},
	            {field: 'beforeElec', title: '上次电表数', align: 'center', width: '150', formatter: function (value, row, index) {
	            	/*if(isNull(value)){
	            		value = '-';
	            	}*/
	            	return '<a style="word-wrap:break-word;">'+value+'</a>';
	            }},
	            {field: 'nowElec', title: '本次电表数', align: 'center', width: '150', formatter: function (value, row, index) {
	            	/*if(isNull(value)){
	            		value = '-';
	            	}*/
	            	return '<a style="word-wrap:break-word;">'+value+'</a>';
	            }},
	            {field: 'nowTolalElec', title: '本次用电量', align: 'center', width: '150', formatter: function (value, row, index) {
	            	/*if(isNull(value)){
	            		value = '-';
	            	}*/
	            	return '<a style="word-wrap:break-word;">'+value+'</a>';
	            }},
	            {field: 'electricUnitPrice', title: '电费单价(元)', align: 'center', width: '150', formatter: function (value, row, index) {
	            	/*if(isNull(value)){
	            		value = '-';
	            	}*/
	            	return '<a style="word-wrap:break-word;">'+value+'</a>';
	            }},
	            {field: 'nowTolalMoney', title: '本次电费(元)', align: 'center', width: '150', formatter: function (value, row, index) {
	            	/*if(isNull(value)){
	            		value = '-';
	            	}*/
	            	return '<a style="word-wrap:break-word;">'+value+'</a>';
	            }},
	            {field: 'JieyuMoney', title: '预交电费结余(元)', align: 'center', width: '150', formatter: function (value, row, index) {
	            	/*if(isNull(value)){
	            		value = '-';
	            	}*/
	            	return '<a style="word-wrap:break-word;">'+value+'</a>';
	            }},
	            {field: 'totalQianMoney', title: '共计欠电费(元)', align: 'center', width: '150', formatter: function (value, row, index) {
	            	/*if(isNull(value)){
	            		value = '-';
	            	}*/
	            	return '<a style="word-wrap:break-word;">'+value+'</a>';
	            }},
	            {field: 'electricType', title: '缴费类型', align: 'center', width: '150', formatter: function (value, row, index) {
	            	if(isNull(value)){
	            		value = '-';
	            	}
	            	return '<a style="word-wrap:break-word;">'+value+'</a>';
	            }
        }],
        onLoadSuccess: function(data){  //加载成功时执行
        	if(data.returnCode!=0){
        		qiao.bs.msg({msg:data.returnMessage,type:'danger'});
        	}
        }
    });
}

function eventInit(){

	//回车模糊搜索
	$('body').keydown(function() {
        if (event.keyCode == "13") {//keyCode=13是回车键
        	var params = {
        			limit : 10,
        			offset : 0,
        			searchParams : $("#searchParams").val()
        	}
        	AjaxPostUtil.request({url : path+"23ec3172230b4f4899a656b65072e41f", params : params, type : 'json', callback : function(json){
        		if(json.returnCode == 0){
        			console.log(json);
        			$('#messageTable').bootstrapTable('refresh',{url : path+'23ec3172230b4f4899a656b65072e41f'});
        		}else{
        			qiao.bs.msg({msg : '参数错误.', type : 'danger'});
        		}
        	}});
        }
	});
	
	//刷新表单
	$('body').on('click', '#refreshDiv', function(e){
		$('#messageTable').bootstrapTable('refresh',{url : path+'05040ac67de3483682465077b8273449'});
		qiao.bs.msg({msg : "刷新成功.", type : 'success'});
	});
}

